﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <script type="text/javascript">
        //var Singleton = (function () {

        //    var instance;

        //    function createInstance() {
        //        var object = new Object("I am the instance");
        //        return object;
        //    }

        //    return {
        //        getInstance: function () {
        //            //alert(this.constructor === Singleton);
        //            var self = this;
        //            if (!instance) {
        //                instance = createInstance();
        //            }

        //            return instance;
        //        }
        //    };
        //})();

        function Singleton() {
            //this.instance = undefined;
        }
        Singleton.getInstance = function () {
            if (!this.instance) {
                this.instance = new Object();
            }

            return this.instance;
        }

        function run() {

            var instance1 = Singleton.getInstance();
            var instance2 = Singleton.getInstance();

            alert("Same instance? " + (instance1 === instance2));
        }
        run();
    </script>
</body>
</html>
